package com.caochenlei.graph;

import java.util.Stack;

public class BreadFirstPathsTest {
    public static void main(String[] args) {
        int s = 0;//从s点开始走
        int n = 6;//图g的顶点数
        Graph G = new Graph(n);
        G.addEdge(0, 2);
        G.addEdge(0, 1);
        G.addEdge(2, 1);
        G.addEdge(2, 3);
        G.addEdge(2, 4);
        G.addEdge(3, 5);
        G.addEdge(3, 4);
        G.addEdge(0, 5);

        BreadFirstPaths paths = new BreadFirstPaths(G, s);
        for (int v = s; v < n; v++) {
            if (paths.hasPathTo(v)) {
                Stack<Integer> stack = paths.pathTo(v);
                System.out.print(s + " to " + v + ": ");
                while (!stack.isEmpty()) {
                    if (stack.size() == 1) {
                        System.out.print(stack.pop() + "\n");
                    } else {
                        System.out.print(stack.pop() + "->");
                    }
                }
            }
        }
    }
}
